<template>
  <div class="loading-container">
    <div class="loading-content">
      <div class="loading-spinner">
        <div class="spinner-icon"></div>
      </div>
      <div class="loading-text">
        <h3>{{ loadingText }}</h3>
        <p>{{ loadingSubText }}</p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';

const route = useRoute();
const loadingText = ref('正在加载系统资源');
const loadingSubText = ref('请稍候...');

// 可以在这里添加不同的加载文本
const loadingTexts = [
  '正在加载用户数据',
  '正在初始化系统',
  '正在配置路由',
  '即将进入系统'
];

// 动态更改加载文本
onMounted(() => {
  // 检查是否有redirect参数
  if (route.params.redirect) {
    loadingSubText.value = `准备导航至: ${route.params.redirect}`;
  }

  let index = 0;
  const interval = setInterval(() => {
    loadingText.value = loadingTexts[index++ % loadingTexts.length];
  }, 1500);

  // 清理定时器
  setTimeout(() => {
    clearInterval(interval);
  }, 10000);
});
</script>

<style scoped>
.loading-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
  background-color: #f8f9fa;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.loading-spinner {
  margin-bottom: 2rem;
}

.spinner-icon {
  width: 50px;
  height: 50px;
  border: 4px solid transparent;
  border-top-color: #409eff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  color: #303133;
}

.loading-text h3 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.loading-text p {
  font-size: 1rem;
  color: #606266;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style> 